define(function (require) {
    var _common = require('common/main');
    var _config = require('common/config');
    var _send = _common.sendRequest;
    function init() {
    	$('#mod_place_confirm').click(_mod_zone_place);
    	var _param = {};
    	_send("listRegion.ajax",_param,_place_mod_region_render);
    	_send("listBus.ajax",_param,_place_mod_bus_render);
    }
    
    function _place_mod_bus_render(data)
    {
    	var _html = '';
    	var zoneparentid = $('#place_mod_zonebusid').val();
    	var _len = data.length;
    	for (var i = 0; i < _len; i++) 
    	{
    		var _item = data[i];
    		_html += '<option value="';
    		_html += _item.id;
			_html += '"';
			if(zoneparentid==_item.id)
			{
				_html += ' selected';
			}
			_html += '>';
    		_html += _item.busName;
    		_html += '</option>';
    	}
    	$('#place_mod_bus').html(_html);
    }
    
    function _place_mod_region_render(data)
    {
    	var _html = '';
    	var zoneparentid = $('#place_mod_zoneregionid').val();
    	var _len = data.length;
    	for (var i = 0; i < _len; i++) 
    	{
    		var _item = data[i];
    		_html += '<option value="';
    		_html += _item.id;
			_html += '"';
			if(zoneparentid==_item.id)
			{
				_html += ' selected';
			}
			_html += '>';
    		_html += _item.name;
    		_html += '</option>';
    	}
    	$('#place_mod_region').html(_html);
    }
    
    function _mod_zone_place()
    {
    	//get from session or cookie
    	var _userid = 0;
    	var _zonename = $('#place_mod_zonename').val();
    	var _placeid = $('#place_mod_zoneplaceid').val();
    	var _pickstart = $('#place_mod_pickstart').val();
    	var _pickend = $('#place_mod_pickend').val();
    	var _regionid = $('#place_mod_region option:selected').attr("value");
    	var _busid = $('#place_mod_bus option:selected').attr("value");
    	var _sequence = $('#place_mod_sequence').val();
    	var _param = _common.stringify({
			userid : _userid,
			zonename : _zonename,
			region : _regionid,
			bus : _busid,
			pickstart : _pickstart,
			pickend : _pickend,
			sequence : _sequence,
			zoneid : _placeid
		});
    	_send("updateZoneplace.ajax",_param,_update_place_render);
    }
    
    function _update_place_render(data)
    {
    	if(data)
		{
    		alert("修改成功");
    		window.close();
		}
    	else
		{
    		alert("修改失败，请修改后重新提交");
		}
    }
    
    return { init: init };
});